package net.biancheng.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.biancheng.common.annotation.Log;
import net.biancheng.common.core.BaseController;
import net.biancheng.common.core.CommonResult;
import net.biancheng.common.enums.BusinessType;
import net.biancheng.bean.SysDictData;
import net.biancheng.service.ISysDictDataService;
import net.biancheng.common.core.page.TableDataInfo;

/**
 * 字典数据Controller
 * 
 * @author lb
 * @date 2023-11-13
 */
@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController
{
    @Autowired
    private ISysDictDataService sysDictDataService;

    /**
     * 查询字典数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDictData sysDictData)
    {
        startPage();
        List<SysDictData> list = sysDictDataService.selectSysDictDataList(sysDictData);
        return getDataTable(list);
    }

    /**
     * 根据字典类型查询字典数据列表
     */
    @GetMapping("/list/{dictType}")
    public CommonResult listByDictType(@PathVariable String dictType)
    {
        List<SysDictData> list = sysDictDataService.selectSysDictDataListByDictType(dictType);
        return CommonResult.success(list);
    }

    /**
     * 获取字典数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable Long id)
    {
        return CommonResult.success(sysDictDataService.selectSysDictDataById(id));
    }

    /**
     * 新增字典数据
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "字典数据", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody SysDictData sysDictData)
    {
        return toResult(sysDictDataService.insertSysDictData(sysDictData));
    }

    /**
     * 修改字典数据
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "字典数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody SysDictData sysDictData)
    {
        return toResult(sysDictDataService.updateSysDictData(sysDictData));
    }

    /**
     * 删除字典数据
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "字典数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toResult(sysDictDataService.deleteSysDictDataByIds(ids));
    }
}
